import 'package:dio/dio.dart';
import 'package:flutterdemo/1demo/common/utils/log_util.dart';


class LogsInterceptors extends InterceptorsWrapper {
  @override
  onRequest(RequestOptions options) async{
    Map<String, dynamic> headers = Map();
    // 添加header
    options.headers.addAll(headers);
    print("request base url: ${options.baseUrl}");
    print("request url: ${options.path}");
    print('request header: ' + options.headers.toString());
    if (options.data != null) {
      print('request parameter: ' + options.data.toString());
    }
    return options;
  }

  @override
  onResponse(Response response)async {
    if (response != null) {
      var responseStr = response.toString();
//      print("response: " + responseStr); 显示不全
      LogUtil.v("response: " + responseStr);
    }

    return response; // continue
  }

  @override
  onError(DioError err) async{
    print('请求异常: ' + err.toString());
    print('请求异常信息: ' + err.response?.toString() ?? "");
    return err;
  }
}




